<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>Document</title>
    <script src="http://api.map.baidu.com/api?v=2.0&ak=ejAxjzIYdAcyuITvlYybrfQVyZgcANrB"></script>
    <style>
        body,html{
            height: 100%;
        }
        *{
            margin: 0;

        }
        #box{
            width: 100%;
            height: 80%;
            background-color: yellow;
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <button id="btn">点击</button>
    <p id="p">你好</p>
</body>
<script>
    var btn = document.getElementById("btn");
    var p = document.getElementById("p");
    var n = 0
    // btn.onclick = function(){
        
        var map = new BMap.Map("box");
        navigator.geolocation.getCurrentPosition(function(p){
            var a = p.coords;
            var myPoint = new BMap.Point(a.longitude,a.latitude);
            var convertor = new BMap.Convertor();
            var pointArr = [];
            alert(a.longitude+','+a.latitude)
            pointArr.push(myPoint);
            convertor.translate(pointArr,2,5,function(data){
                if(data.status==0){
                    var bPoint = new BMap.Point(data.points[0].longitude,data.points[0].latitude);
                    map.centerAndZoom(bPoint,9);
                    var marker = new BMap.Marker(bPoint);        
                    map.addOverlay(marker);
                    alert(data.points[0].longitude+','+data.points[0].latitude)
                }else{
                    alert(data.status)
                }
            })
        })
        map.enableScrollWheelZoom();





    // }
</script>

</html>